package com.bobo.controller.admin;
import com.bobo.dto.VoucherPageQueryDTO;
import com.bobo.entity.Voucher;
import com.bobo.result.Result;
import com.bobo.service.VoucherService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("admin/admin/voucher")
@Api(tags="优惠券相关接口")
@RestController("adminVoucherController")
public class VoucherController {

    @Autowired
    private VoucherService voucherService;

    /**
     * 添加优惠券
     * @param voucher
     * @return
     */

    @PostMapping("/add")
    public Result addVoucher(@RequestBody Voucher voucher) {
        voucherService.addVoucher(voucher);
        return Result.success();
    }

    /**
     * 优惠券分页查询
     * @param voucherPageQueryDTO
     * @return
     */

    @GetMapping("/list")
    private Result<List<Voucher>> getVoucherByPage(VoucherPageQueryDTO voucherPageQueryDTO){
        List<Voucher> list = voucherService.getVoucherByPage(voucherPageQueryDTO);
        return Result.success(list);
    }

    /**
     * 优惠券修改状态
     * @param status
     * @param id
     * @return
     */
    @PutMapping("/status/{status}/{id}")
    private Result updateVoucherStatus(@PathVariable("status") Integer status ,@PathVariable Long id){
        voucherService.updateVoucherStatus(status,id);
        return Result.success();
    }

    /**
     * 更新优惠券
     * @param voucher
     * @return
     */
    @PutMapping("update")
    private Result updateVoucher(@RequestBody Voucher voucher){
        voucherService.updateVoucher(voucher);
        return Result.success();
    }

    /**
     * 删除优惠券
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    private Result deleteVoucher(@PathVariable Long id){
        voucherService.deleteVoucher(id);
        return Result.success();
    }
}
